package com.example.friend.mvp.ui.adapter;

import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.ImageView;
import android.widget.VideoView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.friend.R;
import com.example.friend.mvp.model.ChildCircleModel;
import com.example.friend.mvp.model.CircleTypeModel;
import com.example.friend.mvp.ui.activity.CircleActivity;
import com.example.friend.mvp.ui.activity.ImageDetailActivity;
import com.example.friend.mvp.ui.activity.ImagePreViewActivity;
import com.example.friend.mvp.ui.activity.VideoDetailActivity;
import com.example.friend.mvp.ui.util.GlideUtils;
import com.github.ielse.imagewatcher.ImageWatcherHelper;

import java.util.List;


/**
 * @author: admins
 * date:   2019/6/27 14:22
 * desc:
 */
public class ChildCircleAdapter extends BaseMultiItemQuickAdapter<ChildCircleModel, BaseViewHolder> {
    private ImageView imageView;
    private ImageView videoView;

    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public ChildCircleAdapter(List<ChildCircleModel> data) {
        super(data);
        addItemType(CircleTypeModel.TYPE_IMAGE, R.layout.item_image_one);
        addItemType(CircleTypeModel.TYPE_TEXT, R.layout.item_text);
        addItemType(CircleTypeModel.TYPE_IMAGE_AND_TEXT, R.layout.item_image_and_text);
        addItemType(CircleTypeModel.TYPE_TWO, R.layout.item_circle_two);
        addItemType(ChildCircleModel.TYPE_VIDEO, R.layout.item_video);
    }

    @Override
    protected void convert(BaseViewHolder helper, ChildCircleModel item) {
        imageView = helper.getView(R.id.iv_user);
        videoView = helper.getView(R.id.video_view);
        switch (item.getItemType()) {
            case CircleTypeModel.TYPE_IMAGE:
                GlideUtils.loadImg(mContext, "", imageView, R.mipmap.live);
                break;
            case CircleTypeModel.TYPE_TEXT:
                helper.setText(R.id.tv_content, item.getText());
                helper.setText(R.id.tv_address, item.getAddress());
                break;
            case CircleTypeModel.TYPE_IMAGE_AND_TEXT:
                GlideUtils.loadImg(mContext, "", imageView, R.mipmap.live);
                helper.setText(R.id.tv_text, item.getText());
                break;
            case CircleTypeModel.TYPE_TWO:
                GlideUtils.loadImg(mContext, "", imageView, R.mipmap.live);
                break;
            case CircleTypeModel.TYPE_VIDEO:
                GlideUtils.loadImg(mContext, "", imageView, R.mipmap.live);
                break;
        }
        helper.addOnClickListener(R.id.iv_user);
        helper.addOnLongClickListener(R.id.iv_user);
    }
}
